const db=wx.cloud.database();
const app = getApp();


Page({


  data:{
    dataObj:{},
    avatarUrl : "",
  },

  onLoad: function (options) {
    
  },



//表单

btnsub(res){

  wx.showLoading({
    title: '数据加载中',
    mask: true,
    success: (res) => {},
    fail: (res) => {},
    complete: (res) => {},
  })


  var {name,school,years,bio}=res.detail.value
  
   getApp().globalData.name= name
   getApp().globalData.faculty= school
   getApp().globalData.grade= years
   getApp().globalData.content= bio
   
  console.log(name,school,years,bio)

   var that= this
  db.collection("user").where({
      name:name
    }).get({
      success:res=>{
        console.log(res)
        that.setData({
          dataObj:res.data
        })
      }
    })
console.log(this.data)
  
var a= this.data.dataObj
console.log(a)
if(a === undefined) {
    db.collection("user").add({
      data:{
      name:name,
      school:school,
      years:years,
      bio:bio
      }
      }).then(res=>{console.log(res)
    })
 }
 else {
   wx.navigateTo({
     url: 'pages/wrongpage/wrongpage',
   })
 }

  wx.hideLoading({
    success: (res) => {},
    fail: (res) => {},
    complete: (res) => {},
  })

},

  getPersonalInfo() {
    http.get(`/personal_info`, {}, res => {
      console.log(res.data.data);
      this.setData({
        user: res.data.data
      })
      wx.setStorageSync('user', res.data.data);
    });
  },


  
  data:{
    avatarUrl : "",
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    
      var that = this;
      wx.getUserInfo({
        success: function(res) {
          console.log(res);
          
          var userInfo = res.userInfo
          console.log(userInfo);
         
          var avatarUrl = userInfo.avatarUrl
         
          that.setData({
          
            avatarUrl : avatarUrl,
           
          })
        }
      })
    },



   

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },


  showpersonal(){

    
          
    

    wx.navigateTo({
      url: '/pages/show/showpersonal',

    })
  },

  chooseImg:function () {
    var that = this
    wx.chooseImage({
    sourceType: sourceType[this.data.sourceTypeIndex],
    sizeType: sizeType[this.data.sizeTypeIndex],
    success: function(res) {
    var tempFilePaths = res.tempFilePaths[0]
    console.log(res.tempFilePaths)
    that.setData({imageList: res.tempFilePaths[0]})
    }
    })
    },
})
